{{- /*
This shortcode creates a block of code with syntax highlighting.

@returns {template.HTML}

@examples

  ```bash
  echo "ext_$(date +%s%N | sha512sum | fold -w 8 | head -n 1)"
  ```
*/ -}}

{{ $attr := (.Attributes) }}
{{ $type := ((.Type) | default "plaintext") }}
{{ $inner := ((trim (.Inner) "\n\r") | chomp) }}
{{ $ordinal := (.Ordinal) }}

{{ $cp := ((printf "clipboard-%s-%d" (delimit (shuffle (seq 11 99)) "") ($ordinal)) | md5) }}

{{ if (or ($attr.title) ($attr.file)) }}

  <div class="shortcode mb-3 shortcode-codeblock
  shortcode-codeblock-{{ ($ordinal) }} shortcode-codeblock-{{ ($type) }}">
    <div class="card overflow-hidden" data-bs-theme="dark">
      <div class="card-header">
        <div class="d-flex align-items-center">
          <div class="flex-shrink-0">
            <i class="fas fa-file-code fa-fw"></i>
          </div>
          <div class="flex-grow-1 mx-2">
              {{ with ($attr.title) }}<h5 class="mb-0">{{ . }}</h5>{{ end }}
              {{ with ($attr.file) }}<code>{{ . }}</code>{{ end }}
          </div>
          <div class="flex-shrink-0">
            <ul class="list-inline mb-0">
              <li class="list-inline-item" data-bs-tooltip data-bs-title='{{ (i18n "copy") }}'>
                <a class="text-body" href="#"
                   data-fn="clipboard" data-clipboard-target="#cp-{{ ($cp) }}"
                   role="button" aria-label='{{ (i18n "copy") }}'>
                  <i class="fas fa-copy fa-fw"></i>
                </a>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="card-body p-0 overflow-auto" id="cp-{{ ($cp) }}">{{ (highlight ($inner) ($type)) }}</div>
    </div>
  </div>

{{ else }}

  <div class="shortcode mb-3 shortcode-codeblock shortcode-codeblock-{{ ($ordinal) }}
{{ with ($type) }}shortcode-codeblock-{{ . }}{{ end }}">
    <div class="d-flex overflow-hidden">
      <div class="flex-grow-1 rounded overflow-hidden bg-body-tertiary text-body"
           id="cp-{{ ($cp) }}" data-bs-theme="dark">{{ (highlight ($inner) ($type) ($attr)) }}</div>
      <div class="flex-shrink-0">
        <ul class="list-inline mb-0">
          <li class="list-inline-item" data-bs-tooltip data-bs-title='{{ (i18n "copy") }}'>
            <a class="text-body" href="#"
               data-fn="clipboard" data-clipboard-target="#cp-{{ ($cp) }}"
               role="button" aria-label='{{ (i18n "copy") }}'>
              <i class="fas fa-copy fa-fw"></i>
            </a>
          </li>
        </ul>
      </div>
    </div>
  </div>

{{ end }}
